<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
    	$login=I('post.login');
		$pass=md5(I('post.pass'));
		if(!empty($login) && !empty($pass)){
			$db=D('member');
			$list=$db->where("`login`='{$login}' and `pass`='{$pass}'")->find();
			if(empty($list)){
				$this->error('登录失败');
			}else{
				$this->success('登录成功',U('home/index/getlist'));
			}
//			echo  $db->getLastSql();
//			print_r($list);
		}
        $this->display('login');
    }
	
	public function getlist(){
			$db=D('member');
			$list=$db->where()->select();
			$this->assign('list',$list);
			$this->display('list');		
	}
	public function del(){
			$id=I('get.id');			
			if(empty($id)){				
				$this->error('删除失败');die;
			}			
			$db=D('member');
			$list=$db->where("id='{$id}'")->delete();
			//echo  $db->getLastSql();
			if(empty($list)){
				$this->error('删除失败');die;
			}else{
				$this->success('删除成功',U('home/index/getlist'));die;
			}	
	}
	public function reg(){
		$data['login']=I('post.login');
		$data['pass']=md5(I('post.pass'));
		if(!empty($data['login']) && !empty($data['pass'])){
			$db=D('member');			
			$list=$db->add($data);
			if(empty($list)){
				$this->error('新增失败');
			}else{
				$this->success('新增成功',U('home/index/getlist'));die;
			}
		}
		$this->display('reg');
		
	}
}